#include <iostream>
#include <boost/lexical_cast.hpp>

using std::cin;
using std::cout;
using std::endl;

enum Parity {EVEN, ODD};

Parity
flip(Parity in)
{
    return (in == EVEN) ? ODD : EVEN;
}

std::string
parity_to_s(Parity in)
{
    return (in == EVEN) ? "EVEN" : "ODD";
}

class RollingLuhnCheck
{
public:
    RollingLuhnCheck();

    void feed(int i);
    bool is_valid();
    int  get_check();

    std::string inspect();
private:
    int    sum;
    Parity parity;
};

RollingLuhnCheck::RollingLuhnCheck()
{
    sum    = 0;
    parity = ODD;
}

void
RollingLuhnCheck::feed(int i)
{
    i *= (this->parity == EVEN) ? 2 : 1;

    while (i > 0) {
        int lsd = i % 10;

        sum += lsd;

        i /= 10;
    }

    this->parity = flip(this->parity);
}

bool
RollingLuhnCheck::is_valid()
{
    return (sum % 10) == 0;
}

int
RollingLuhnCheck::get_check()
{
    return 10 - (sum % 10);
}

std::string
RollingLuhnCheck::inspect()
{
    std::string data = "";

    data += ("parity:" + parity_to_s(this->parity));
    data += (",sum:"   + boost::lexical_cast<std::string>(sum));
    data += (",check:" + boost::lexical_cast<std::string>(get_check()));

    return data;
}

int
main(int argc, char **argv)
{
    RollingLuhnCheck rlc;

    rlc.feed(1);
    rlc.feed(7);
    rlc.feed(6);
    rlc.feed(2);
    rlc.feed(4);
    rlc.feed(8);

    cout << rlc.inspect() << endl;
}
